# coding: utf-8
from Item import Item

SQLITE_DB = 'amac.db'

SQLITE_CREATE_TABLE = '''CREATE TABLE IF NOT EXISTS COMPANY
       (id TEXT     NOT NULL,
       managerName           TEXT    NOT NULL,
       artificialPersonName            TEXT     NOT NULL,
       registerNo            TEXT     NOT NULL,
       establishDate            TEXT     NOT NULL,
       managerHasProduct            TEXT     NOT NULL,
       url            TEXT     NOT NULL,
       registerDate            TEXT     NOT NULL,
       registerAddress            TEXT     NOT NULL,
       registerProvince            TEXT     NOT NULL,
       registerCity            TEXT     NOT NULL,
       regAdrAgg            TEXT     NOT NULL,
       fundCount            TEXT     NOT NULL,
       fundScale            TEXT     NOT NULL,
       paidInCapital            TEXT     NOT NULL,
       subscribedCapital            TEXT     NOT NULL,
       hasSpecialTips            TEXT     NOT NULL,
       inBlacklist            TEXT     NOT NULL,
       hasCreditTips            TEXT     NOT NULL,
       regCoordinate            TEXT     NOT NULL,
       officeAddress            TEXT     NOT NULL,
       officeProvince            TEXT     NOT NULL,
       officeCity            TEXT     NOT NULL,
       primaryInvestType            TEXT     NOT NULL
       );'''

SQLITE_INSERT = "INSERT INTO COMPANY (id,managerName,artificialPersonName,registerNo,establishDate,managerHasProduct,url,registerDate,registerAddress,registerProvince,registerCity,regAdrAgg,fundCount,fundScale,paidInCapital,subscribedCapital,hasSpecialTips,inBlacklist,hasCreditTips,regCoordinate,officeAddress, officeProvince, officeCity,primaryInvestType)"

SQLITE_DROP_TABLE = "DROP TABLE IF EXISTS COMPANY"

HEADERS = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
    'Connection': 'keep-alive',
    'Content-Length': '2',
    'Content-Type': 'application/json',
    'Cookie': 'gsScrollPos-209=',
    'DNT': '1',
    'Host': 'gs.amac.org.cn',
    'Origin': 'http://gs.amac.org.cn',
    'Referer': 'http://gs.amac.org.cn/amac-infodisc/res/pof/manager/managerList.html',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest'
}


def build_sqlite_insert_sql(data):
    return SQLITE_INSERT + " VALUES (" + data + ")"


def handle(data):
    return Item(data['id'], data['managerName'], data['artificialPersonName'], data['registerNo'],
                data['establishDate'], data['managerHasProduct'], data['url'], data['registerDate'],
                data['registerAddress'], data['registerProvince'], data['registerCity'], data['regAdrAgg'],
                data['fundCount'], data['fundScale'], data['paidInCapital'], data['subscribedCapital'],
                data['hasSpecialTips'], data['inBlacklist'], data['hasCreditTips'], data['regCoordinate'],
                data['officeAddress'], data['officeProvince'], data['officeCity'], data['primaryInvestType'])


def build_post_url(count):
    return 'http://gs.amac.org.cn/amac-infodisc/api/pof/manager?page=' + str(count) + '&size=20'
